############################################################
#Replication: Honig Weaver A Race to the Top               #
#														   #
#             International Organization    
#                Replication Archive, Uploaded June 6 2019 #
############################################################

drop _all
set more off, permanently


*cd "/path/to/replication/directory/"

use "Honig Weaver Race to the Top replication data June 2019"


 
***Generating Gallardi Independence
egen independence_Gallardi=rowmean(termofoffice sourceofbudget indepenceformallystated cabinet)


 **Calculations before reshape

gen lastoverall=overall_11
replace lastoverall=overall_12 if lastoverall==.
replace lastoverall=overall_13 if lastoverall==.
replace lastoverall=overall_14 if lastoverall==.
replace lastoverall=overall_15 if lastoverall==.
replace lastoverall=overall_16 if lastoverall==.
rename lastoverall firstoverall

gen lastoverall=overall_16
replace lastoverall=overall_15 if lastoverall==.
replace lastoverall=overall_14 if lastoverall==.
replace lastoverall=overall_13 if lastoverall==.
replace lastoverall=overall_12 if lastoverall==.
replace lastoverall=overall_11 if lastoverall==.


egen ATIyearsum=rownonmiss(overall_11-overall_16)

gen maxchange=lastoverall-firstoverall
replace maxchange=. if ATIyearsum==1

list org_name if lastoverall==firstoverall


**Figure 2:  Net Change by Agency on ATI over Coverage Period
hist maxchange
*Edited in graph editor

***2nd through 4th column of summary Table 2
sum maxchange independence_Gallardi aidagency_dummy
sutex2 maxchange independence_Gallardi aidagency_dummy, min sav(sum1) replace

***Histogram for Appendix Figure A1

hist independence_Gallardi, scheme (s1mono) bin (10) xtit (Gilardi Independence Scale)

 ***Reshaping from agency to agency-year for main analysis
 
/*
 *Install "renvars" command if not previously installed
 findit dm88_1
 *Click to install
 */
 
 
 order *_w_*, last
 *Shortening varnames for stubs to come first
 foreach var of varlist i1_foia_11-i39_condition_16 {
    rename `var' `=substr("`var'",4,30)'
	}
	
renvars _*, map(substr("@", 2, 20))

renvars overall_11_new-overall_16_new, prefix (recalc)
renvars recalc*, postdrop(4)

**Renaming for consistency
rename rank_15 ranking_15
rename rank_16 ranking_16


***Rationalizing years
rename *06 *2006 
rename *07 *2007
rename *08 *2008
rename *09 *2009
rename *10 *2010
rename *_11 *_2011
rename *_12 *_2012
rename *_13 *_2013
rename *_14 *_2014
rename *_15 *_2015
rename *_16 *_2016
rename *2020* *20*

***Using only the agency level variables from aiddata; 

renvars a_aiddata*, predrop(2)


 reshape long ATIactivitylevel_ ranking_ category_ categoryranking_ distancetothreshold_ gaptonextbest_ rankchange_ rankchangeno15_ altscaleRucheta_ altscaleRucheta2_ timeliness_ updatecount_ databasequality_ comprehensiveness_ overstrat_ access_ model_ schedule_ budget_ commitments_ annualreport_ database_ allactivities_ ctrydatabase_ sublocation_ pexpend_ aexpend_ bgtid_ overall_ recalcoverall_ dejure_ results_ organizationlevel_ countrylevel_ activitylevel_ foia_ iati_ allocation_ procurement_ totalbgt_ disbgt_ audit_ ctrystrat_ ctybgt_ eval_ result_ implementer_ collaboration_ flowtype_ aidtype_ fintype_ uniqueid_ title_ description_ sector_ pdates_ adate_ aidstatus_ overallcost_ transac_ status_ contact_ web_ impact_ obj_ beneficiaries_ condition_ bgtdoc_ tenders_ contract_ mou_ designdoc_ aiddata_sum aiddata_coverage aiddata_avgtitle aiddata_avglong aiddata_tadl aiddata_totalrowcount aiddata_finagencycount aiddata_financingagency aiddata_titlecount aiddata_title aiddata_longdescount aiddata_longdescription aiddata_flownamecount aiddata_flowname aiddata_overthreshold aiddata_thresholdpercent, i(org_id org_name country_name country_id orgtype_name orgtype_id) j(year)

 *Removing stub underscore
renvars *_, postdrop(1)
 
 
 **Setting the panel

 xtset org_id year

 
 **Generating dummies for FEs
 
 tab country_name, gen (countrydum)
tab year, gen (yeardum)

 
 ***Summary stats table - 2nd part (first row of Table 2)
 
 sum overall  
sutex2 overall, min sav(sum2) replace


**Figure 1: Histogram of all ATI scores in sample
hist overall
*Edited in Graph Editor for presentation version


*Table 3: Performance on the ATI by Aid and Non-aid Agencies

*Generating interaction term for agency independence and aid/non-aid dummy
gen GallXaidagency=independence_Gallardi*aidagency_dummy

**Replacing missing country_ids for those without countries (will mean country FEs equiv to org FEs for agencies that do not belong to countries)
replace country_id=org_id if country_id==.


eststo clear
eststo: reg overall aidagency_dummy i.year, vce (cluster year)
eststo: reg overall aidagency_dummy i.country_id i.year, vce (cluster year)
eststo: reg overall independence_Gallardi aidagency_dummy GallXaidagency i.year, vce (cluster year)
eststo: reg overall independence_Gallardi aidagency_dummy GallXaidagency i.country_id i.year, vce (cluster year)
esttab using Table3Dec2018.tex, se label star(* 0.10 ** 0.05 *** 0.01) r2 obslast replace booktabs

**Testing interaction models (Model 3 and 4) under interflex (as asked for by acceptance letter)

interflex overall independence_Gallardi aidagency_dummy yeardum1-yeardum11 
interflex overall independence_Gallardi aidagency_dummy yeardum1-yeardum11 countrydum1-countrydum43
*Note dropping (vce cluster) - documentation implies compatible but get error message when I try to implement

****Table 4: Using ATI as Treatment

**Cleaning two instances where 'long description' (one of the component measures) is over 100%; should be top-censored at 1 (full disclosure), apparent error in AidData's internal calculation of measure

replace aiddata_longdescription=1 if aiddata_longdescription>1 & aiddata_longdescription!=.

*Generating activity level score from aidata data

egen AidDataAgencyActivityLevel=rowmean(aiddata_financingagency aiddata_title aiddata_longdescription aiddata_flowname)
replace AidDataAgencyActivityLevel=AidDataAgencyActivityLevel*100

**Turning existence of ATI score into a dummy variable, showing inclusion in ATI in a given year

gen treatment=1 if overall!=.
replace treatment=0 if treatment==.


**Interaction term, treatment and independence
gen treatmentXind=independence_Gallardi*treatment
gen treatmentXindXaidagency=independence_Gallardi*treatment*aidagency_dummy
gen treatmentXaidagency=treatment*aidagency_dummy

label variable treatment "Covered by ATI in Year (Treatment)"
label variable AidDataAgencyActivityLevel "AidData Activity Level Scale"
label variable treatmentXind "Treatment*Independence (Gilardi)"
label variable treatmentXaidagency "Treatment*Aid Agency"


**Summary stats for AidDataActivityLevel

*Row 5 of Table 2 (Summary stats)
sutex2 AidDataAgencyActivityLevel, min sav(sum2) replace

**Correlation between AidData and ATI scale measure (as asked for in editors' conditional acceptance letter)
corr overall AidDataAgencyActivityLevel 


***Table 4 Version

*clustered on year


eststo clear
eststo: reg AidDataAgencyActivityLevel treatment  i.org_id, vce (cluster year)
eststo: reg AidDataAgencyActivityLevel treatment  i.org_id yeardum1-yeardum11, vce (cluster year)
eststo: reg AidDataAgencyActivityLevel treatment  treatmentXaidagency i.org_id, vce (cluster year)
eststo: reg AidDataAgencyActivityLevel treatment  treatmentXaidagency yeardum1-yeardum11 i.org_id,  vce (cluster year)
eststo: reg AidDataAgencyActivityLevel treatment treatmentXind i.org_id if aidagency_dummy==0 ,  vce (cluster year)
eststo: reg AidDataAgencyActivityLevel treatment treatmentXind yeardum1-yeardum11 i.org_id if aidagency_dummy==0,  vce (cluster year)
eststo: reg AidDataAgencyActivityLevel treatment treatmentXind i.org_id if aidagency_dummy==1,  vce (cluster year)
eststo: reg AidDataAgencyActivityLevel treatment treatmentXind yeardum1-yeardum11 i.org_id if aidagency_dummy==1,  vce (cluster year)
esttab using FinalTable4Dec2018.tex, se label star(* 0.10 ** 0.05 *** 0.01) r2 obslast replace noomitted drop (yeardum* *org_id*) booktabs


***Interflex of key interactions in Table 4

tab org_id, gen (orgdum)


interflex AidDataAgencyActivityLevel treatment  aidagency_dummy yeardum1-yeardum11 orgdum1-orgdum84
*Consistent with Table 4, Model 4

interflex AidDataAgencyActivityLevel treatment  independence_Gallardi yeardum1-yeardum11 orgdum1-orgdum84 if aidagency_dummy==0
**Consistent with Table 4 Model 6 results, no effect

interflex AidDataAgencyActivityLevel treatment  independence_Gallardi yeardum1-yeardum11 orgdum1-orgdum84 if aidagency_dummy==1
***Consistent with Table 4 Model 8 results, effect found


*Indicator-by-indicator analysis for response to R1, Conditional Acceptance response
reg aiddata_financingagency treatment treatmentXind  i.org_id if aidagency_dummy==1,  vce (cluster year)
reg  aiddata_title  treatment treatmentXind  i.org_id if aidagency_dummy==1,  vce (cluster year)
reg aiddata_longdescription treatment treatmentXind  i.org_id if aidagency_dummy==1,  vce (cluster year)
reg aiddata_flowname treatment treatmentXind i.org_id if aidagency_dummy==1,  vce (cluster year)



***Figures 3 and 4: Marginal effect of independence on aid and non-aid agencies

/*
*Install grinter if not yet present
findit grinter
*Click install
*/

*Figure 3: Non-Aid Agencies (regression rerun as grinter had trouble with ", fe"; instead replaced with i.org_id)
xtreg AidDataAgencyActivityLevel treatment treatmentXind yeardum1-yeardum11 independence_Gallardi i.org_id if aidagency_dummy==0
grinter treatment, inter (treatmentXind) const02(independence_Gallardi) min(0) max (1) nomean scheme(s1mono) ytitle(Marginal Effect of ATI Treatment on AidData Scale) title (Figure 3: Marginal Effect of Treatment by Independence for Non-aid Agencies)

*Figure 4: Aid Agencies
xtreg AidDataAgencyActivityLevel treatment treatmentXind yeardum1-yeardum11 independence_Gallardi i.org_id if aidagency_dummy==1
grinter treatment, inter (treatmentXind) const02(independence_Gallardi) min(0) max (1) nomean scheme(s1mono) ytitle(Marginal Effect of ATI Treatment on AidData Scale) title (Figure 4: Marginal Effect of Treatment by Independence for Aid Agencies)
